package com.aat.dxfy.redis.test.keycount;

import redis.clients.jedis.Jedis;

public class TaskConsumer implements Runnable {
	private Jedis jedis;

	public TaskConsumer(Jedis jedis) {
		this.jedis = jedis;
	}

	public void run() {

		while (true) {
			try {
				Thread.sleep(2000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			
			// 将本次任务从暂存队列"tmp-queue"中清除
			String key = jedis.rpop("tmp-queue");
			
			System.out.println(key + ":" + jedis.exists(key));
			
			if (jedis.exists(key)) {
				String s = jedis.get(key);
				Integer i = Integer.parseInt(s) + 1;
				jedis.set(key, "" + i);
				jedis.expire(key, 3);
			}
			System.out.println(key + ":" + jedis.get(key));
			
		}

	}

}